<!-- 搜索项目 -->
<template>
  <h-select-input-popup
    ref="hSelectInputPopup"
    v-model="val"
    v-bind="$attrs"
    v-on="$listeners"
    :params="queryParams"
    :keywords.sync="keywords"
    :getList="getList"
    :searchPlaceholder="placeholder"
    @getDetail="getDetail"
    @change="$emit('change', $event)"
  >
    <template v-slot:default="{ item }">
      <view class="project-item">
        <view class="option">
          <view class="lf">单据编号</view>
          <view class="rl">{{ item.billNo }}</view>
        </view>
        <view class="option">
          <view class="lf">使用日期</view>
          <view class="rl">{{ item.useDate }}</view>
        </view>
        <view class="option">
          <view class="lf">关联项目</view>
          <view class="rl">{{ item.projectId_dictText }}</view>
        </view>
        <view class="option">
          <view class="lf">借款用途</view>
          <view class="rl">{{ item.purpose_dictText }}</view>
        </view>
        <view class="option column">
          <view class="lf">借款金额（元）/还款金额（元）/报销冲账（元）</view>
          <view class="rl">{{ item.money }}</view>
        </view>
      </view>
    </template>
  </h-select-input-popup>
</template>

<script>
import { erpFinanceBorrowBillList } from '@/api/index.js'
import { erpFinanceBorrowBillInfo } from '@/api/index.js'

export default {
  name: 'HSelectOilCardInputPopup',
  data() {
    return {
      getList: erpFinanceBorrowBillList,
      params: {
        column: 'createTime',
        order: 'desc',
        pageNo: 1,
        pageSize: 10,
      },
      keywords: '',
      placeholder: '请输入单据编号'
    }
  },
  model: {
    prop: 'value',
    event: 'input',
  },
  props: {
    value: {
      type: [String, Number, Array],
      default: null,
    },
    teamId: {
      type: [String, Number],
      default: null,
    },
    companyId: {
      type: [String, Number],
      default: null,
    },
    checkStatus: {
      type: [String, Number],
      default: null,
    },
    settleAccounts: {
      type: [String, Number],
      default: null,
    },
    proposer: {
      type: [String, Number],
      default: null,
    },
  },
  watch: {
    keywords: {
      handler(val) {
        if (val) {
          // this.params.cardRecipient_dictText = '*' + val + '*'
        } else {
          // this.params.cardRecipient_dictText = ''
        }
      },
      immediate: true,
    },
  },
  computed: {
    val: {
      get() {
        return this.value
      },
      set() {
        this.$emit('input', this.value)
      }
    },
    queryParams() {
      const params = {
        ...this.params,
      }
      if (this.keywords) {
        params.billNo = this.keywords
      }
      if (this.teamId) {
        params.teamId = this.teamId
      }
      if (this.companyId) {
        params.companyId = this.companyId
      }
      if (this.checkStatus !== null) {
        params.checkStatus = this.checkStatus
      }
      if (this.proposer) {
        params.proposer = this.proposer
      }
      if (this.settleAccounts !== null) {
        params.settleAccounts = this.settleAccounts
      }
      
      return params
    }
  },
  methods: {
    // 获取详情
    getDetail(value) {
      erpFinanceBorrowBillInfo({ id: value }).then((res) => {
        if (res.success) {
          this.$refs.hSelectInputPopup.title = res.result.billNo
          this.$emit('select', {
            data: res.result,
            id: value
          })
        }
      })
    },
  },
}
</script>

<style lang="scss" scoped>

// 按钮
.btn {
  position: fixed;
  bottom: 20rpx;
  width: 95%;
}
.column{
  flex-flow: column;
  .rl{
    margin: 0;
  }
}
</style>
